package ru.myrtle.umf.codegen;

public class GenArtifact<ContextType> {

    private final GenTemplate<ContextType> template;
    private final String charset;

    /*
     *
     */

    public GenArtifact(GenTemplate<ContextType> template, String charset) {
        this.template = template;
        this.charset = charset;
    }

    /*
     *
     */

    public GenTemplate getTemplate() {
        return template;
    }

    public String getCharset() {
        return charset;
    }

    /*
     *
     */

    public void generate(Object object, ResourceDomain fileDomain, GenMonitor monitor, ContextType context)
            throws GenException {

        monitor.templateStarted(
                template.getName()
        );

        Resource resource = fileDomain.getSourceFile(charset);

        boolean processed = template.generate(
                object, resource, context
        );

        if (processed) {
            monitor.templatePerformed(
                    resource.getName()
            );
        }
        else {
            monitor.templateRejected();
        }
    }
}
